﻿using System;
using GeoSketch2.Core;
using System.Windows.Forms;
using System.IO;

namespace GeoSketch2.Archaeo
{
    public partial class MainForm : GeoSketchMainForm
    {
        #region Constructor
        /// <summary>
        /// The main form of the application, the parent MDI form
        /// </summary>
        public MainForm()
        {
            InitializeComponent();

            ParentMenuStrip.Items.AddRange(menuStrip1.Items);
            menuStrip1.Visible = false;

            this.MdiChildActivate += new EventHandler(MainForm_Activated);

            SetActiveItems(Vars.Setup.Forms.MainForm.ActiveMenuItems);
        }

        void MainForm_Activated(object sender, EventArgs e)
        {
            if (this.ActiveMdiChild==null)
            {
                SetActiveItems(Vars.Setup.Forms.MainForm.ActiveMenuItems);
            }
        } 
        #endregion

        #region Events
        /// <summary>
        /// The action when clicking the open file button
        /// </summary>
        public override void OpenFile(object sender, EventArgs e)
        {
            if (this.ActiveMdiChild == null)
            {
                OpenFileDialog ofd = new OpenFileDialog();
                ofd.Filter = Vars.Setup.FileIO.GSK.OpenSaveDialogDefaultExtensionFilter;
                DialogResult dr = ofd.ShowDialog();
                if (dr == DialogResult.OK)
                {
                    ArchaeoProject Project=FileIO.ReadGSK(ofd.FileName);
                    if (Project != null)
                    {
                        DrawingForm df = new DrawingForm(this, Project, ofd.FileName);
                        df.Show();
                    }
                }
            }
            else
            {
                base.OpenFile(sender, e);
            }
        }

        /// <summary>
        /// The action when clicking the new file button
        /// </summary>
        public override void New(object sender, EventArgs e)
        {
            NewProjectForm npf = new NewProjectForm(this);
            npf.ShowDialog();
        }
 
        #endregion

        private void rectifyImageToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            DialogResult dr = ofd.ShowDialog();
            if (dr == DialogResult.OK)
            {
                ImageRectificationForm irf = new ImageRectificationForm(this, ofd.FileName);
                irf.Show();
            }
        }
    }
}
